<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" th:href="@{/css/font.css}">
    <link rel="stylesheet" th:href="@{/css/xadmin.css}">
    <script th:src="@{/webjars/jquery/3.5.1/jquery.min.js}"></script>
    <script th:src="@{/js/ions_alert.js}"></script>
    <script th:src="@{/common/common.js}"></script>
    <script th:src="@{/js/sweetalert.min.js}"></script>
    <link rel="stylesheet" th:href="@{/css/sweetalert.css}">
</head>

<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">演示</a>
        <a>
          <cite>导航元素</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <dd class="layui-form layui-col-md12 x-so">
            <input value="" type="text" name="username" placeholder="请输入登录名" autocomplete="off"
                   class="layui-input" id="username">
            <input value="" type="text" name="name" placeholder="请输入姓名" autocomplete="off"
                   class="layui-input" id="name">
            <input value="" type="text" name="email" placeholder="请输入邮箱" autocomplete="off"
                   class="layui-input" id="email">
            <input value="" type="text" name="phone" placeholder="请输入电话" autocomplete="off"
                   class="layui-input" id="phone">
            <input value="" type="text" name="address" placeholder="请输入地址" autocomplete="off"
                   class="layui-input" id="address">
            <button class="layui-btn" lay-submit="" lay-filter="search" id="search"><i class="layui-icon">&#xe615;</i></button>
        </dd>
    </div>
    <xblock>
        <button class="layui-btn" onclick="x_admin_show('添加菜单','userAdd',600,700)"><i
            class="layui-icon"></i>添加
        </button>
        <span class="x-right" style="line-height:40px">共有数据：<span id="many"></span> 条</span>
    </xblock>
    <table class="layui-table">
        <thead>
        <tr>
            <th width="6%">
                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i
                        class="layui-icon">&#xe605;</i></div>
            </th>
            <th>登录名</th>
            <th>姓名</th>
            <th>积分</th>
            <th>邮箱</th>
            <th>电话</th>
            <th>地址</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody id="userList">
        </tbody>
    </table>
    <div class="page">
        <div>
            <span class="current" id="curr">共0页</span>
            <a class="prev" href="javaScript:" onclick="pageGo('start') "><&lt;</a>
            <a class="prev" href="javaScript:" onclick="pageGo('forward')">&lt;</a>
            <span class="current" id="currentPage">1</span>
            <a class="next" href="javaScript:" onclick="pageGo('next')">></a>
            <a class="next" href="javaScript:" onclick="pageGo('end')">&gt;&gt;</a>
        </div>
    </div>

</div>
<script>

    $(function () {

        findUserBy(null,null,null,null,null,null,null,null);
        $("#search").click(function () {
            let curr = $("#curr").text();
            let currentPage = $("#currentPage").text();
            let username = $("#username").val();
            let name = $("#name").val();
            let email = $("#email").val();
            let phone = $("#phone").val();
            let address = $("#address").val();
            findUserBy(curr,currentPage,'search',username,name,email,phone,address);
        })

    });


    function pageGo(param) {
        let curr = $("#curr").text();
        let currentPage = $("#currentPage").text();
        let username = $("#username").val();
        let name = $("#name").val();
        let email = $("#email").val();
        let phone = $("#phone").val();
        let address = $("#address").val();
        // console.log("123");
        findUserBy(curr,currentPage,param,username,name,email,phone,address);
    }

    function deleteUserConfirm(username) {
        let b = window.confirm("确认要注销吗？");
        if(b){
            // console.log(username);
            $.ajax({
                url: "/admin/user/deleteUser",
                type: "DELETE",
                data: {
                    username:username
                },
                success:function (ResultInfo) {
                    // console.log(ResultInfo);
                    alert(ResultInfo.message);
                    if(ResultInfo.flag){
                        window.location.reload();
                    }
                }
            })
        }
    }

    function findUserBy(curr,currentPage,param,username,name,email,phone,address) {
        $.ajax({
            url: "pageUserQuery",
            type: "PUT",
            data: {
                param:param,
                curr:curr,
                currentPage:currentPage,
                username: username,
                name: name,
                email: email,
                phone: phone,
                address: address
            },
            success:function (resultInfo) {
                if(resultInfo.flag){
                    var text = '';
                    for (let i = 0; i < resultInfo.data.list.length; i++) {
                        text += '<tr>\n' +
                            '            <td>\n' +
                            '                <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id=\'2\'>\n' +
                            '                    <i class="layui-icon">&#xe605;</i>\n' +
                            '                </div>\n' +
                            '            </td>\n' +
                            '            <td>'+resultInfo.data.list[i].username+'</td>\n' +
                            '            <td>'+resultInfo.data.list[i].name+'</td>\n' +
                            '            <td>'+resultInfo.data.list[i].points+'</td>\n' +
                            '            <td>'+resultInfo.data.list[i].email+'</td>\n' +
                            '            <td>'+resultInfo.data.list[i].phone+'</td>\n' +
                            '            <td>'+resultInfo.data.list[i].address+'</td>\n' +
                            '            <td class="td-manage">\n' +
                            '                <a href="javaScript:" onclick="x_admin_show(\'编辑用户\',\'userEdit?username=\'+'+'\''+resultInfo.data.list[i].username+'\''+',600,500)"'+
                            '                   style="cursor: pointer" class="layui-btn layui-btn-mini layui-btn-normal">\n' +
                            '                    <i class="layui-icon">&#xe642;</i>编辑\n' +
                            '                </a>\n' +
                            '                <a onclick="deleteUserConfirm('+'\''+resultInfo.data.list[i].username+'\''+')" style="cursor: pointer" class="layui-btn layui-btn-mini layui-btn-danger delete_btn">\n' +
                            '                    <i class="layui-icon">&#x1006;</i>删除\n' +
                            '                </a>\n' +
                            '            </td>\n' +
                            '        </tr>';
                    }
                    text += '';

                    $("#userList").html(text);

                    $("#currentPage").text(resultInfo.data.currentPage);
                    $("#many").text(resultInfo.data.totalCount);


                    $("#curr").html('共'+resultInfo.data.totalPage+'页')
                    // console.log(resultInfo.data.list[0]);

                    // console.log(resultInfo.data);
                }
            }
        })
    }

</script>
</body>

</html>